package fast.loader;

import java.io.Serializable;

import fast.data.Stat;
import fast.data.StatBlock;
import fast.data.WeaponType;
import fast.ranking.ItemEquippedEP;

public class Item extends StatBlock implements Serializable
{ 	
	private static final long serialVersionUID = 2036349958956071874L;
	private int id;
	private String name = "";
	private String tag = "";
	private String icon = "";
	private String tooltip = "";
	
	public Socket[] gemSlot = new Socket[3];
	private SocketBonus socketBonus = null;
	
	// weapon stats
	private int minDmg = 0;
	private int maxDmg = 0;
	private double speed = 0;
	private double dps = 0;
	private WeaponType weaponType = null;
	
	// set
	private String set = "";
	private int inventorySlot = 0;		// slot or type???
	private int itemClass = 0;			// classs (Weapons, 4 = Armor)
	private int itemSubClass = 0;		// subclass (Thrown=16 Leather Armor = 2)
	private String gearBuff;
	private int numSockets;
	private int quality;
	private int itemLevel;
	private int heroic = 0;
	private int reqSkill;
	private int reqClass;
	
	private boolean upgradable;
	private int upgradeLevel = 0;
	
	private double ep;
	private ItemEquippedEP suggestion;
	
	public Item(){

	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName(){
		return this.name;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getId() {
		return id;
	}
	public void setSet(String set) {
		this.set = set;
	}
	public String getSet(){
		return this.set;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public String getIcon() {
		return icon;
	}
	public Socket[] getGemSlot(){
		return gemSlot;
	}
	public void setSocketBonus(SocketBonus sb){
		socketBonus = sb;
	}
	public SocketBonus getSocketBonus(){
		return socketBonus;
	}
	public void setInventorySlot(int int1) {
		inventorySlot = int1;
	}
	public int getInventorySlot() {
		return inventorySlot;
	}
	public void setItemSubClass(int itemSubClass) {
		this.itemSubClass = itemSubClass;
	}
	public int getItemSubClass() {
		return itemSubClass;
	}
	public void setGearBuff(String name2) {
		this.gearBuff = name2;
	}
	public String getGearBuff(){
		return gearBuff;
	}
	public void setNumSockets(int length) {
		this.numSockets = length;
	}
	public int getNumSockets(){
		return numSockets;
	}
	public void setSpeed(double s){
		speed = s;
	}
	public double getSpeed(){
		return speed;
	}
	public void setDps(double d){
		dps = d;
	}
	public double getDps(){
		return dps;
	}
	public void setMinDmg(int min){
		minDmg = min;
	}
	public int getMinDmg(){
		return minDmg;
	}
	public void setMaxDmg(int max){
		maxDmg = max;
	}
	public int getMaxDmg(){
		return maxDmg;
	}
	public void setQuality(int quality) {
		this.quality = quality;
	}
	public int getQuality() {
		return quality;
	}
	public void setItemLevel(int itemLevel) {
		this.itemLevel = itemLevel;
	}
	public int getItemLevel() {
		return itemLevel;
	}
	public int getOriginalItemLevel() {
		int ilvl = itemLevel;
		int lvl_by = this.quality == 3 ? 8 : 4;
		ilvl -= lvl_by * upgradeLevel;
		return ilvl;
	}
	public void setHeroic(int heroic) {
		this.heroic = heroic;
	}
	public int getHeroic() {
		return heroic;
	}
	public void setItemClass(int itemClass) {
		this.itemClass = itemClass;
	}
	public int getItemClass() {
		return itemClass;
	}
	public void setTooltip(String tooltip) {
		this.tooltip = tooltip;
	}
	public String getTooltip() {
		return tooltip;
	}
	public void setReqSkill(int reqSkill) {
		this.reqSkill = reqSkill;
	}
	public int getReqSkill() {
		return reqSkill;
	}
	public int getReqClass() {
		return reqClass;
	}
	public void setReqClass(int reqClass) {
		this.reqClass = reqClass;
	}
	public String getStatString(){
		StringBuffer string = new StringBuffer();
		for(Stat stat : Stat.possibleReforgeStats){
			if(getStat(stat) > 0)
				string.append(stat.getName() + ", ");
		}
		if(string.length() > 2){
			return string.substring(0, string.length()-2);
		}else
			return "";
	}
	public double getEp() {
		return ep;
	}
	public void setEp(double ep) {
		this.ep = ep;
	}
	public boolean isUpgradable() {
		return upgradable;
	}
	public void setUpgradable(boolean upgradable) {
		this.upgradable = upgradable;
	}
	public int getUpgradeLevel() {
		return upgradeLevel;
	}
	public void setUpgradeLevel(int upgradeLevel) {
		this.upgradeLevel = upgradeLevel;
	}
	public int getMaxUpgradeLevel() {
		return this.quality == 3 ? 1 : 2;
	}
	public void setWeaponType(WeaponType w) {
		weaponType = w;
	}
	public void setWeaponType() {
		if(itemSubClass == 0)
			new Exception("Can't set Weapon type whitout item subclass id");
		for(WeaponType wtype : WeaponType.values()){
			if(wtype.getIndex() == itemSubClass){
				weaponType = wtype;
				break;
			}
		}
	}
	public WeaponType getWeaponType() {
		return weaponType;
	}
	public String getTag() {
		return tag;
	}
	public void setTag(String tag) {
		this.tag = tag;
	}
	// predict the source of the item, with ilvl and tag
	public String getSource(){
		if(this.itemLevel <= 483){
			if(this.tag.equals("LFR"))
				return "T14 LFR";
			else
				return "Dungeon, Scenario, World";
		}else if(this.itemLevel >= 489){
			if(this.tag.equals("H") && this.itemLevel <= 524)
				return "T14 Heroic";
			else if(this.tag.equals("LFR"))
				return "T15 LFR";
			else if(this.itemLevel <= 511)
				return "T14 Normal";
			
		}
		
		return "";
	}
	
	public String toString(){
		return this.name;
	}
	public void setSuggestion(ItemEquippedEP iep) {
		this.suggestion = iep;
	}
	
	public ItemEquippedEP getSuggestion() {
		return this.suggestion;
	}
}
